package net.esj.basic.utils;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

public final class Validators {

	/**
	 * 
	 * @see net.esj.basic.utils.StringUtils#hasText
	 */
	@Deprecated
	public static boolean isEmpty(String str) {
		if (str == null || "".equals(str)) {
			return true;
		}
		return false;
	}
	
	public static boolean isEmpty(Serializable ser) {
		if(ser == null){
			return true;
		}
		if(ser instanceof String){
			return isEmpty((String)ser);
		}
		return false;
	}
	
	public static boolean isEmpty(Object[] objs) {
		return isEmpty(objs, false);
	}
	
	public static boolean isEmpty(Object[] objs,boolean checkAllElement){
		if (objs == null) {
			return true;
		}
		if(objs.length==0){
			return true;
		}
		if(objs.length==1 && isEmpty(objs[0])){//元素为1
			return true;
		}
		if(checkAllElement){
			for(Object o : objs){
				if(!isEmpty(o)){
					return false;
				}
			}
		}else{
			return false;
		}
		return true;
	}
	
	public static boolean isEmpty(Collection collection){
		return (collection == null || collection.isEmpty());
	}
	
	public static boolean isEmpty(Map map){
		return (map == null || map.isEmpty());
	}
	
	public static boolean isEmpty(Object o){
		if(o==null){
			return true;
		}
		if(o instanceof String){
			return isEmpty((String)o);
		}
		if(o.getClass().isArray()){
			return isEmpty((Object[])o);
		}
		if(o instanceof Collection){
			return isEmpty((Collection)o);
		}
		if(o instanceof Map){
			return isEmpty((Map)o);
		}
		return false;
	}

	public static boolean isBlank(String str){
		return str!=null && "".equals(str);
	}
	
}
